package com.eorchis.module.trainingquestionnaire.domain.json;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.type.TypeReference;

import com.eorchis.utils.JSONUtils;
import com.eorchis.utils.utils.PropertyUtil;

/**
 * 
 * Title: StudentPageInfoUtils<br>
 * Description: 考生试卷工具类<br>
 * Company: ORCHIS<br>
 * Copyright @ 2012 ORCHIS .All rights reserved.<br>
 * @see 该类实现了对考生试卷的一些常用读取等操作
 * @author Max
 * @createDate 2014-09-09
 * @version $Revision:$
 */
public class StudentPageInfoUtils {

	/**
	 * json字符串转换为考生试卷信息
	 * 
	 * @param content
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-12
	 */
	public static final StudentPageInfo str2StudentPageInfo(String content) throws Exception {
		if (!PropertyUtil.objectNotEmpty(content)) {
			return null;
		}
		StudentPageInfo info = JSONUtils.jsonToObj(content, new TypeReference<StudentPageInfo>() {
		});
		return info;
	}

	/**
	 * json字符串转换为试卷信息
	 * 
	 * @param content
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-12
	 */
	public static final PaperInfo str2PageInfo(String content) throws Exception {
		if (!PropertyUtil.objectNotEmpty(content)) {
			return null;
		}
		PaperInfo info = JSONUtils.jsonToObj(content, new TypeReference<PaperInfo>() {
		});
		return info;
	}

	/**
	 * json字符串转换为考生答案数组
	 * 
	 * @param content
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-19
	 */
	public static final List<StudentAnswerSelect> str2StuAnswerList(String content) throws Exception {
		if (!PropertyUtil.objectNotEmpty(content)) {
			return null;
		}
		List<StudentAnswerSelect> stuAnswerList = JSONUtils.jsonToObj(content, new TypeReference<List<StudentAnswerSelect>>() {
		});
		return stuAnswerList;
	}

	/**
	 * 学生考题答案集合字符串转换为list
	 * 
	 * @param content
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-12
	 */
	public static final List<String> studentAnswerStr2List(String content) throws Exception {
		if (!PropertyUtil.objectNotEmpty(content)) {
			return new ArrayList<String>();
		}
		List<String> info = JSONUtils.jsonToObj(content, new TypeReference<List<String>>() {
		});
		return info;
	}

	/**
	 * 实体类转换为json字符串
	 * 
	 * @param obj
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-12
	 */
	public static final String obj2Json(Object obj) throws Exception {
		return JSONUtils.objToJson(obj);
	}

}
